--- title: "L1-094 剪切粘贴" created: 2025-11-28 tags: - 算法 --- # L1-094 剪切粘贴 ## 题目 [L1-094 剪切粘贴](https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7?problemSetProblemId=1649748772841508869&page=0) ![[image-391676c1.png]] ## 思路分析 ## 代码实现 ```cpp #include using namespace std; #define endl '\n' using ll = long long; using ull = unsigned long long; using PII = pair; using Pll = pair; int dx[4]= {-1,0,1,0},dy[4]= {0,1,0,-1}; const int inf = 0x3f3f3f3f; int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); string s;cin>>s; // int st,ed;cin>>st>>ed; // st--,ed--; // int len=ed-st+1; // cout<>l>>r; // int crl=s.find(l); // int crr=s.find(r); // cout<>n; while(n--){ int st,ed,len;cin>>st>>ed; st--,ed--;len=ed-st+1; string jq=s.substr(st,len); s.erase(st,len); string l,r;cin>>l>>r; int len_l=l.size(); int len_r=r.size(); int zt=s.size(); int s_len=s.size(); for(int i=len_l;i<=s_len-len_r;i++){ if(i-len_l<0) continue; string pre=s.substr(i-len_l,len_l); string suf=s.substr(i,len_r); if(pre==l && suf==r){ zt=i; break; } } s.insert(zt,jq); } cout<